package freecomm.fileexplorer;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import freecomm.fileexplorer.R.array;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @author Junwei.Xu
 * 
 */
public class FileExplorer extends Activity
{
    /**
     * LVCBSimpleAdapter A local class extends simpleAdapter for fix the problem
     * witch is about CheckBox in ListView
     * 
     * @author: Junwei.Xu
     */
    class LVCBSimpleAdapter extends SimpleAdapter
    {
        private LayoutInflater mInflater;
        private boolean withCB = false;
        private boolean selectAll = false;
        private boolean[] isItemChecked;
        private boolean isDataChanged = true;

        public LVCBSimpleAdapter(Context context,
                List<? extends Map<String, ?>> data, int resource,
                String[] from, int[] to)
        {
            super(context, data, resource, from, to);

            mInflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent)
        {
            convertView = super.getView(position, convertView, parent);
            CheckBox mCB = (CheckBox) convertView
                    .findViewById(R.id.mainListCheckBox);
            if (withCB)
            {
                if (selectAll)
                {
                    mCB.setChecked(true);
                } else
                {
                    if (isItemChecked[position])
                    {
                        mCB.setChecked(true);
                    } else
                    {
                        mCB.setChecked(false);
                    }
                }
                mCB.setVisibility(View.VISIBLE);
            } else
            {
                mCB.setVisibility(View.GONE);
            }

            return convertView;
        }

        public boolean isChecked(int position)
        {
            return isItemChecked[position];
        }

        public boolean isSelectAll()
        {
            return selectAll;
        }

        public boolean isWithCB()
        {
            return withCB;

        }

        @Override
        public void notifyDataSetChanged()
        {
            super.notifyDataSetChanged();
            if (isDataChanged)
            {
                isItemChecked = new boolean[getCount()];
            }
            isDataChanged = true;
        }

        private void setDataNotChange()
        {
            isDataChanged = false;
        }

        public void setisChecked(int position)
        {
            if (isSelectAll())
            {
                for (int i = 0; i < getCount(); i++)
                {
                    isItemChecked[i] = true;
                }
                selectAll = false;
            }
            isItemChecked[position] = !isItemChecked[position];
        }

        public void setSelectAll(boolean selectAll)
        {
            this.selectAll = selectAll;
        }

        public void setWithCB(boolean withCB)
        {
            this.withCB = withCB;
        }

        public boolean[] getItemChecked()
        {
            return isItemChecked;
        }
    }

    class CopySingleFile extends AsyncTask<File, Void, Void>
    {
        @Override
        protected Void doInBackground(File... files)
        {
            try
            {
                if (files[1].exists())
                {
                    files[1].delete();
                }
                copyFile(files[0], files[1]);
            } catch (IOException e)
            {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result)
        {
            copyType = NOT_COPY;
            drawListView();
            reCalSize();
        }

        private void copyFile(File sourceFile, File targetFile)
                throws IOException
        {
            /* new the file input stream and it's buffer stream */
            FileInputStream input = new FileInputStream(sourceFile);
            BufferedInputStream inBuff = new BufferedInputStream(input);

            /* new the file output stream and it's buffer stream */
            FileOutputStream output = new FileOutputStream(targetFile);
            BufferedOutputStream outBuff = new BufferedOutputStream(output);

            /* buffer array */
            byte[] b = new byte[1024 * 5];
            int len;
            while ((len = inBuff.read(b)) != -1)
            {
                outBuff.write(b, 0, len);
            }
            /* refresh output buffer stream */
            outBuff.flush();

            /* close all stream */
            inBuff.close();
            outBuff.close();
            output.close();
            input.close();
        }

    }

    class MoveSingleFile extends AsyncTask<File, Void, Void>
    {

        /*
         * (non-Javadoc)
         * 
         * @see android.os.AsyncTask#doInBackground(Params[])
         */
        @Override
        protected Void doInBackground(File... files)
        {
            try
            {
                if (files[1].exists())
                {
                    files[1].delete();
                }
                copyFile(files[0], files[1]);
            } catch (IOException e)
            {
                e.printStackTrace();
            }
            files[0].delete();
            return null;
        }

        private void copyFile(File sourceFile, File targetFile)
                throws IOException
        {
            /* new the file input stream and it's buffer stream */
            FileInputStream input = new FileInputStream(sourceFile);
            BufferedInputStream inBuff = new BufferedInputStream(input);

            /* new the file output stream and it's buffer stream */
            FileOutputStream output = new FileOutputStream(targetFile);
            BufferedOutputStream outBuff = new BufferedOutputStream(output);

            /* buffer array */
            byte[] b = new byte[1024 * 5];
            int len;
            while ((len = inBuff.read(b)) != -1)
            {
                outBuff.write(b, 0, len);
            }
            /* refresh output buffer stream */
            outBuff.flush();

            /* close all stream */
            inBuff.close();
            outBuff.close();
            output.close();
            input.close();
        }

        @Override
        protected void onPostExecute(Void result)
        {
            copyType = NOT_COPY;
            drawListView();
            reCalSize();
        }

    }

    class DeleteFolder extends AsyncTask<File, Void, Void>
    {

        /*
         * (non-Javadoc)
         * 
         * @see android.os.AsyncTask#doInBackground(Params[])
         */
        @Override
        protected Void doInBackground(File... params)
        {
            deleteFile(params[0]);
            return null;
        }

        @Override
        protected void onPostExecute(Void result)
        {
            copyType = NOT_COPY;
            drawListView();
            reCalSize();
        }

        private void deleteFile(File mFile)
        {
            if (mFile.isFile())
            {
                mFile.delete();
            } else if (mFile.isDirectory())
            {
                File files[] = mFile.listFiles();
                for (int i = 0; i < files.length; i++)
                {
                    this.deleteFile(files[i]);
                }
            }
            mFile.delete();
        }
    }

    class CopySingleFolder extends AsyncTask<File, Void, Void>
    {

        /*
         * (non-Javadoc)
         * 
         * @see android.os.AsyncTask#doInBackground(Params[])
         */
        @Override
        protected Void doInBackground(File... files)
        {
            try
            {
                if (files[1].exists())
                {
                    deleteFolder(files[1]);
                }
                copyDirectiory(files[0].getPath(), TEMP_FOLDER);
                copyDirectiory(TEMP_FOLDER, files[1].getPath());
                deleteFile(new File(TEMP_FOLDER));
            } catch (IOException e)
            {
                e.printStackTrace();
            }
            return null;
        }

        private void copyFile(File sourceFile, File targetFile)
                throws IOException
        {
            /* new the file input stream and it's buffer stream */
            FileInputStream input = new FileInputStream(sourceFile);
            BufferedInputStream inBuff = new BufferedInputStream(input);

            /* new the file output stream and it's buffer stream */
            FileOutputStream output = new FileOutputStream(targetFile);
            BufferedOutputStream outBuff = new BufferedOutputStream(output);

            /* buffer array */
            byte[] b = new byte[1024 * 5];
            int len;
            while ((len = inBuff.read(b)) != -1)
            {
                outBuff.write(b, 0, len);
            }
            /* refresh output buffer stream */
            outBuff.flush();

            /* close all stream */
            inBuff.close();
            outBuff.close();
            output.close();
            input.close();
        }

        @Override
        protected void onPostExecute(Void result)
        {
            copyType = NOT_COPY;
            drawListView();
            reCalSize();
        }

        private void deleteFile(File mFile)
        {
            if (mFile.isFile())
            {
                mFile.delete();
            } else if (mFile.isDirectory())
            {
                File files[] = mFile.listFiles();
                for (int i = 0; i < files.length; i++)
                {
                    this.deleteFile(files[i]);
                }
            }
            mFile.delete();
        }

        private void copyDirectiory(String sourceDir, String targetDir)
                throws IOException
        {
            /* new target directory */
            (new File(targetDir)).mkdirs();
            /* get file list of current path */
            File[] file = (new File(sourceDir)).listFiles();
            for (int i = 0; i < file.length; i++)
            {
                if (file[i].isFile())
                {
                    /* source file */
                    File sourceFile = file[i];
                    /* target file */
                    File targetFile = new File(
                            new File(targetDir).getAbsolutePath()
                                    + File.separator + file[i].getName());
                    copyFile(sourceFile, targetFile);
                }
                if (file[i].isDirectory())
                {
                    /* the folder which will be copied */
                    String dir1 = sourceDir + "/" + file[i].getName();
                    /* the folder which will be copied to */
                    String dir2 = targetDir + "/" + file[i].getName();
                    copyDirectiory(dir1, dir2);
                }
            }
        }
    }

    class MoveSingleFolder extends AsyncTask<File, Void, Void>
    {

        @Override
        protected Void doInBackground(File... files)
        {
            try
            {
                if (files[1].exists())
                {
                    deleteFolder(files[1]);
                }
                copyDirectiory(files[0].getPath(), TEMP_FOLDER);
                copyDirectiory(TEMP_FOLDER, files[1].getPath());
                deleteFile(new File(TEMP_FOLDER));
                deleteFile(files[0]);
            } catch (IOException e)
            {
                e.printStackTrace();
            }
            return null;
        }

        private void copyFile(File sourceFile, File targetFile)
                throws IOException
        {
            /* new the file input stream and it's buffer stream */
            FileInputStream input = new FileInputStream(sourceFile);
            BufferedInputStream inBuff = new BufferedInputStream(input);

            /* new the file output stream and it's buffer stream */
            FileOutputStream output = new FileOutputStream(targetFile);
            BufferedOutputStream outBuff = new BufferedOutputStream(output);

            /* buffer array */
            byte[] b = new byte[1024 * 5];
            int len;
            while ((len = inBuff.read(b)) != -1)
            {
                outBuff.write(b, 0, len);
            }
            /* refresh output buffer stream */
            outBuff.flush();

            /* close all stream */
            inBuff.close();
            outBuff.close();
            output.close();
            input.close();
        }

        @Override
        protected void onPostExecute(Void result)
        {
            copyType = NOT_COPY;
            drawListView();
            reCalSize();
        }

        private void deleteFile(File mFile)
        {
            if (mFile.isFile())
            {
                mFile.delete();
            } else if (mFile.isDirectory())
            {
                File files[] = mFile.listFiles();
                for (int i = 0; i < files.length; i++)
                {
                    this.deleteFile(files[i]);
                }
            }
            mFile.delete();
        }

        private void copyDirectiory(String sourceDir, String targetDir)
                throws IOException
        {
            /* new target directory */
            (new File(targetDir)).mkdirs();
            /* get file list of current path */
            File[] file = (new File(sourceDir)).listFiles();
            for (int i = 0; i < file.length; i++)
            {
                if (file[i].isFile())
                {
                    /* source file */
                    File sourceFile = file[i];
                    /* target file */
                    File targetFile = new File(
                            new File(targetDir).getAbsolutePath()
                                    + File.separator + file[i].getName());
                    copyFile(sourceFile, targetFile);
                }
                if (file[i].isDirectory())
                {
                    /* the folder which will be copied */
                    String dir1 = sourceDir + "/" + file[i].getName();
                    /* the folder which will be copied to */
                    String dir2 = targetDir + "/" + file[i].getName();
                    copyDirectiory(dir1, dir2);
                }
            }
        }
    }

    class MoveMutiple extends AsyncTask<ArrayList<String>, String, Void>
    {
        private int mFlag = 0;// 0:not choose 1: replace 2:skip 3:cancel
        private AlertDialog mAD;
        private AlertDialog.Builder mBuilder = new AlertDialog.Builder(
                FileExplorer.this);
        private android.content.DialogInterface.OnClickListener skipButtonClickListener = new android.content.DialogInterface.OnClickListener()
        {

            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                // TODO Auto-generated method stub
                mFlag = 2;
            }
        };
        private android.content.DialogInterface.OnClickListener replaceButtonClickListener = new android.content.DialogInterface.OnClickListener()
        {

            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                // TODO Auto-generated method stub
                mFlag = 1;
            }
        };
        private android.content.DialogInterface.OnClickListener cancelButtonClickListener = new android.content.DialogInterface.OnClickListener()
        {

            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                // TODO Auto-generated method stub
                mFlag = 3;
            }
        };

        /*
         * (non-Javadoc)
         * 
         * @see android.os.AsyncTask#onPreExecute()
         */
        @Override
        protected void onPreExecute()
        {
            mBuilder.setMessage("")
                    .setNeutralButton(R.string.instead, skipButtonClickListener)
                    .setPositiveButton(R.string.skip,
                            replaceButtonClickListener)
                    .setNegativeButton(R.string.cancel,
                            cancelButtonClickListener);
        }

        /*
         * (non-Javadoc)
         * 
         * @see android.os.AsyncTask#doInBackground(Params[])
         */
        @Override
        protected Void doInBackground(ArrayList<String>... mPaths)
        {
            for (int i = 0; i < mPaths[0].size(); i++)
            {
                mFlag = 0;
                String mPath = mPaths[0].get(i).toString();
                String mFileName = mPath.substring(mPath.lastIndexOf('/') + 1);
                File mTarFile = new File(getPath() + '/' + mFileName);
                if (mTarFile.exists())
                {
                    publishProgress(mFileName);
                    while (0 == mFlag)
                    {

                    }
                    switch (mFlag)
                    {
                    case 1:
                        moveSingle(new File(mPath), mTarFile);
                        break;
                    case 2:
                        // TODO skip
                        Log.i("info", "2");
                        break;
                    case 3:
                        // TODO cancel

                        Log.i("info", "3");
                        return null;
                    default:
                        break;
                    }
                } else
                {
                    // TODO not exists
                    moveSingle(new File(mPath), mTarFile);
                }
            }
            return null;
        }

        /*
         * (non-Javadoc)
         * 
         * @see android.os.AsyncTask#onProgressUpdate(Progress[])
         */
        @Override
        protected void onProgressUpdate(String... values)
        {
            mBuilder.setMessage(values[0] + " "
                    + getResources().getString(R.string.file_exist));
            mAD = mBuilder.create();
            mAD.show();
        }

        /*
         * (non-Javadoc)
         * 
         * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
         */
        @Override
        protected void onPostExecute(Void result)
        {
            copyType = NOT_COPY;
            reCalSize();
            drawListView();
        }

        private void moveSingle(File mSrcFile, File mTarFile)
        {
            if (mSrcFile.isDirectory())
            {
                new MoveSingleFolder().execute(mSrcFile, mTarFile);
            } else
            {
                new MoveSingleFile().execute(mSrcFile, mTarFile);
            }
        }

    }

    class CopyMutiple extends AsyncTask<ArrayList<String>, String, Void>
    {
        private int mFlag = 0;// 0:not choose 1: replace 2:skip 3:cancel
        private AlertDialog mAD;
        private AlertDialog.Builder mBuilder = new AlertDialog.Builder(
                FileExplorer.this);
        private android.content.DialogInterface.OnClickListener skipButtonClickListener = new android.content.DialogInterface.OnClickListener()
        {

            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                // TODO Auto-generated method stub
                mFlag = 2;
            }
        };
        private android.content.DialogInterface.OnClickListener replaceButtonClickListener = new android.content.DialogInterface.OnClickListener()
        {

            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                // TODO Auto-generated method stub
                mFlag = 1;
            }
        };
        private android.content.DialogInterface.OnClickListener cancelButtonClickListener = new android.content.DialogInterface.OnClickListener()
        {

            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                // TODO Auto-generated method stub
                mFlag = 3;
            }
        };

        /*
         * (non-Javadoc)
         * 
         * @see android.os.AsyncTask#doInBackground(Params[])
         */
        @Override
        protected void onPreExecute()
        {
            mBuilder.setMessage("")
                    .setNeutralButton(R.string.instead, skipButtonClickListener)
                    .setPositiveButton(R.string.skip,
                            replaceButtonClickListener)
                    .setNegativeButton(R.string.cancel,
                            cancelButtonClickListener);
        }

        @Override
        protected Void doInBackground(ArrayList<String>... mPaths)
        {
            // TODO Auto-generated method stub

            for (int i = 0; i < mPaths[0].size(); i++)
            {
                mFlag = 0;
                String mPath = mPaths[0].get(i).toString();
                String mFileName = mPath.substring(mPath.lastIndexOf('/') + 1);
                File mTarFile = new File(getPath() + '/' + mFileName);
                if (mTarFile.exists())
                {
                    publishProgress(mFileName);
                    while (0 == mFlag)
                    {

                    }
                    switch (mFlag)
                    {
                    case 1:
                        copySingle(new File(mPath), mTarFile);
                        break;
                    case 2:
                        // TODO skip
                        Log.i("info", "2");
                        break;
                    case 3:
                        // TODO cancel

                        Log.i("info", "3");
                        return null;
                    default:
                        break;
                    }
                } else
                {
                    // TODO not exists
                    copySingle(new File(mPath), mTarFile);
                }
            }
            return null;
        }

        @Override
        protected void onProgressUpdate(String... values)
        {
            mBuilder.setMessage(values[0] + " "
                    + getResources().getString(R.string.file_exist));
            mAD = mBuilder.create();
            mAD.show();
        }

        private void copySingle(File mSrcFile, File mTarFile)
        {
            if (mSrcFile.isDirectory())
            {
                new CopySingleFolder().execute(mSrcFile, mTarFile);
            } else
            {
                new CopySingleFile().execute(mSrcFile, mTarFile);
            }
        }

        @Override
        protected void onPostExecute(Void result)
        {
            copyType = NOT_COPY;
            reCalSize();
            drawListView();
        }
    }

    /******************************/
    /* delimit identifier --start */
    /******************************/
    /** COPY_MULTIPLE:the flag of copy multiple files */
    private static final int COPY_MULTIPLE = 1;
    /** COPY_SINGLE:the flag of copy single files */
    private static final int COPY_SINGLE_FILE = 2;
    /** MOVE_MULTIPLE:the flag of move multiple files */
    private static final int MOVE_MULTIPLE = 3;
    /** MOVE_SINGLE:the flag of move single files */
    private static final int MOVE_SINGLE_FILE = 4;
    /** MOVE_SINGLE_FOLDER:the flag of move single folder */
    private static final int MOVE_SINGLE_FOLDER = 5;
    /** COPY_SINGLE_FOLDER:the flag of copy single folder */
    private static final int COPY_SINGLE_FOLDER = 6;
    /** NOT_COPY:the flag of not copy now */
    private static final int NOT_COPY = 7;
    /** LIST_ITEM_IMG_MAP_KEY:the key of image resource of list item map */
    protected static final String LIST_ITEM_IMG_MAP_KEY = "img";
    /** LIST_ITEM_TEXT_MAP_KEY:the key of text resource of list item map */
    protected static final String LIST_ITEM_TEXT_MAP_KEY = "text";
    /** SYSTEM_FOLDER_CAMERA:the system folder camera name */
    protected static final String SYSTEM_FOLDER_CAMERA = "Camera";
    /** SYSTEM_FOLDER_DOWNLOAD:the system folder download name */
    protected static final String SYSTEM_FOLDER_DOWNLOAD = "Download";
    /** SYSTEM_FOLDER_VIDEO:the system folder video name */
    protected static final String SYSTEM_FOLDER_VIDEO = "Video";
    /** SYSTEM_FOLDER_PHOTO:the system folder photo name */
    protected static final String SYSTEM_FOLDER_PHOTO = "Photo";
    /** SYSTEM_FOLDER_MUSIC:the system folder music name */
    protected static final String SYSTEM_FOLDER_MUSIC = "Music";
    /** mainListItemList:the main list data list */
    private List<Map<String, Object>> mainListItemList = new ArrayList<Map<String, Object>>();
    /** morePopupMenuItemList:"more" popup menu data list */
    private List<Map<String, Object>> morePopupMenuItemList = new ArrayList<Map<String, Object>>();
    /** contextPopupMenuItemList:context popup menu data list */
    private List<Map<String, Object>> contextPopupMenuItemList = new ArrayList<Map<String, Object>>();
    /** popupMenuDialog:popup menu dialog */
    private AlertDialog popupMenuDialog;
    /** popupMenuListView:popup menu list view */
    private ListView popupMenuListView;
    /** morePopupMenuAdapter:"more" popup menu list adapter */
    private SimpleAdapter morePopupMenuAdapter;
    /** contextPopupMenuAdapter:context popup menu list adapter */
    private SimpleAdapter contextPopupMenuAdapter;
    /** mainListItemAdapter:main list adapter */
    private LVCBSimpleAdapter mainListItemAdapter;
    /** mainListView:main list view */
    private ListView mainListView;
    /** sDNotExistImageView:the image view of SD card not exist */
    private ImageView SDNotExistImageView;
    /** sDNotExistTextView:the text view of SD card not exist */
    private TextView SDNotExistTextView;
    /** progressBar:title progress bar */
    private ProgressBar progressBar;
    /** progressBarText:title progress bar text */
    private TextView progressBarText;
    /** functionButtonBar:function button bar */
    private RelativeLayout functionButtonBar;
    private RelativeLayout bottomBar;
    /** rootTabButton:root button of the path buttons */
    private Button rootTabButton;
    /** tabButtons:path buttons */
    private Button[] tabButtons = new Button[3];
    /** SD_ROOTPATH:the SD card path */
    protected final static String SD_ROOTPATH = "/sdcard";
    private final static String TEMP_FOLDER = SD_ROOTPATH + "/.temp.temp";
    /** pathStringArray:current path string array */
    private List<String> pathStringArray = new ArrayList<String>();
    /** the input dialog */
    private AlertDialog inputDialog;
    /** confirm delete dialog */
    private AlertDialog confirmDeleteDialog;
    /** saveFunctionButton:the "save" function button */
    private Button saveFunctionButton;
    /** cancelFunctionButton:the "cancel" function button */
    private Button cancelFunctionButton;
    /** selectAllFunctionButton:the "select all" function button */
    private Button selectAllFunctionButton;
    /** deleteFunctionButton:the "delete" function button */
    private Button deleteFunctionButton;
    /** moreFunctionButton:the "more " function button */
    private Button moreFunctionButton;
    /** pathBar:the path bar */
    private RelativeLayout pathBar;
    /** popupMenuHeaderTextView:popup menu header text */
    private TextView popupMenuHeaderTextView;
    /** optionMenu:option menu */
    private MyOptionMenu optionMenu;
    /** the interval time of make sure exit program */
    private long exitTime = 0;
    /** the source path of copy or move */
    private String srcPath = "";
    /** the target path of copy or move */
    private String tarPath = "";
    private ArrayList<String> srcPathsArray;
    /** the flag of the type of copy or move */
    private int copyType = 0;
    /** systemFolderMap:system folder map it's real name */
    protected final static Map<String, String> systemFolderMap = new HashMap<String, String>()
    {
        {
            put(SYSTEM_FOLDER_CAMERA, "DCIM");
            put(SYSTEM_FOLDER_DOWNLOAD, "download");
            put(SYSTEM_FOLDER_MUSIC, "music");
            put(SYSTEM_FOLDER_VIDEO, "video");
            put(SYSTEM_FOLDER_PHOTO, "Pictures");
        }
    };
    /** bluePoint:the blue point image view */
    private ImageView bluePoint;
    /** the flag if input dialog is for new folder */
    private boolean isNewFolder = true;
    /** bluePointPositionMap:blue point position map */
    private final static int[] bluePointPositionMap = { 76, 156, 236, 316 };
    /****************************/
    /* delimit identifier --end */
    /****************************/

    /*******************************/
    /* event listener code --start */
    /*******************************/

    /**
     * deleteFunctionButtonClickListener:delete function button click event
     * listener
     */
    private OnClickListener deleteFunctionButtonClickListener = new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            // TODO Auto-generated method stub
            setFunctionbar(true);
            ArrayList<String> mPathsArrayList = getSelectPaths();
            mainListItemAdapter.setWithCB(false);
            mainListItemAdapter.notifyDataSetChanged();
            File mFile;
            for (int i = 0; i < mPathsArrayList.size(); i++)
            {
                mFile = new File(mPathsArrayList.get(i).toString());
                new DeleteFolder().execute(mFile);
            }
        }
    };

    /**
     * cancelFunctionButtonClickListener:cancel function button click event
     * listener
     */
    private OnClickListener cancelFunctionButtonClickListener = new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            // TODO Auto-generated method stub
            setFunctionbar(true);

        }
    };
    /**
     * saveFunctionButtonClickListener:save function button click event listener
     */
    private OnClickListener saveFunctionButtonClickListener = new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            try
            {
                tarPath = getPath();
                switch (copyType)
                {
                case COPY_MULTIPLE:
                    copyMutiple();
                    break;
                case COPY_SINGLE_FILE:
                    copySingleFile();
                    break;
                case MOVE_MULTIPLE:
                    moveMutiple();
                    break;
                case MOVE_SINGLE_FILE:
                    moveSingleFile();
                    break;
                case MOVE_SINGLE_FOLDER:
                    moveSingleFolder();
                    break;
                case COPY_SINGLE_FOLDER:
                    copySingleFolder();
                    break;
                }
                setFunctionbar(false);
            } catch (IOException e)
            {
                e.printStackTrace();
            }
        }
    };

    /** optionMenuItemClickListener:option menu item click event listener */
    private OnItemClickListener optionMenuItemClickListener = new OnItemClickListener()
    {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id)
        {
            switch (position)
            {
            case 0:
                inputDialog.setTitle(getResources().getString(
                        R.string.new_folder));
                isNewFolder = true;
                inputDialog.show();
                optionMenu.dismiss();
                break;
            case 1:
                deleteFunctionButton.setEnabled(false);
                moreFunctionButton.setEnabled(false);
                optionMenu.dismiss();
                mainListItemAdapter.setSelectAll(false);
                mainListItemAdapter.setWithCB(true);
                setFunctionbar(true);
                mainListItemAdapter.notifyDataSetChanged();
                break;
            case 2:
                optionMenu.dismiss();
                sortFileList();
                break;
            }

        }
    };

    /**
     * selectAllFunctionButtonClickListener:select all function button click
     * event listener
     */
    private OnClickListener selectAllFunctionButtonClickListener = new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            mainListItemAdapter
                    .setSelectAll(!mainListItemAdapter.isSelectAll());
            mainListItemAdapter.notifyDataSetChanged();
            if (mainListItemAdapter.selectAll)
            {
                moreFunctionButton.setEnabled(true);
                deleteFunctionButton.setEnabled(true);
            } else
            {
                moreFunctionButton.setEnabled(false);
                deleteFunctionButton.setEnabled(false);
            }
        }
    };

    /**
     * moreFunctionButtonClickListener:more function button click event listener
     */
    private OnClickListener moreFunctionButtonClickListener = new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            getSelectPaths();
            setMorePopupMenu(!containFolder());
        }
    };

    /** mainListItemLongClickListener:main list long click event listener */
    private OnItemLongClickListener mainListItemLongClickListener = new OnItemLongClickListener()
    {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view,
                int position, long id)
        {
            if (!mainListItemAdapter.isWithCB())
            {
                String mFileName = mainListItemList.get(position)
                        .get(LIST_ITEM_TEXT_MAP_KEY).toString();
                if (pathStringArray.size() == 0)
                {
                    if (isSystemFolder(mFileName))
                    {
                        mFileName = systemFolderMap.get(mFileName);
                    }
                }
                File mFile = new File(getPath(mFileName));
                if (mFile.isDirectory())
                {
                    setContextPopupMenu(
                            mainListItemList.get(position)
                                    .get(LIST_ITEM_TEXT_MAP_KEY).toString(),
                            true);
                } else
                    setContextPopupMenu(
                            mainListItemList.get(position)
                                    .get(LIST_ITEM_TEXT_MAP_KEY).toString(),
                            false);
            }

            return false;
        }
    };

    /** contextPopupItemClickListener:context popup menu click event listener */
    private OnItemClickListener contextPopupItemClickListener = new OnItemClickListener()
    {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id)
        {
            switch (position)
            {
            case 1:

                srcPath = getPath();
                if (new File(srcPath + '/' + getContextFile()).isDirectory())
                {
                    copyType = COPY_SINGLE_FOLDER;
                } else
                {
                    copyType = COPY_SINGLE_FILE;
                }
                saveFunctionButton.setEnabled(true);
                setFunctionbar(false);
                popupMenuDialog.dismiss();
                break;
            case 2:
                srcPath = getPath();
                if (new File(srcPath + '/' + getContextFile()).isDirectory())
                {
                    copyType = MOVE_SINGLE_FOLDER;
                } else
                {
                    copyType = MOVE_SINGLE_FILE;
                }
                saveFunctionButton.setEnabled(false);
                setFunctionbar(false);
                popupMenuDialog.dismiss();
                break;
            case 3:
                inputDialog.setTitle(getResources().getString(R.string.rename));
                isNewFolder = false;
                popupMenuDialog.dismiss();
                inputDialog.show();
                break;
            case 4:
                popupMenuDialog.dismiss();
                confirmDeleteDialog.show();
                break;
            case 5:
                popupMenuDialog.dismiss();
                File mFile = new File(getPath(getContextFile()));
                shareFile(mFile);

                break;
            }
        }
    };

    /** morePopupItemClickListener:"more" popup menu click event listener */
    private OnItemClickListener morePopupItemClickListener = new OnItemClickListener()
    {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id)
        {
            switch (position)
            {
            case 1:
                copyType = COPY_MULTIPLE;
                srcPathsArray = getSelectPaths();
                saveFunctionButton.setEnabled(false);
                setFunctionbar(false);
                setFunctionbar(false);
                mainListItemAdapter.setWithCB(false);
                mainListItemAdapter.notifyDataSetChanged();
                popupMenuDialog.dismiss();
                break;
            case 2:
                copyType = MOVE_MULTIPLE;
                srcPathsArray = getSelectPaths();
                saveFunctionButton.setEnabled(false);
                setFunctionbar(false);
                setFunctionbar(false);
                mainListItemAdapter.setWithCB(false);
                mainListItemAdapter.notifyDataSetChanged();
                popupMenuDialog.dismiss();
                break;
            case 3:
                ArrayList<String> mFilePaths = getSelectPaths();
                Intent intent = new Intent(
                        android.content.Intent.ACTION_SEND_MULTIPLE);
                ArrayList<Uri> mUris = getAllUris(mFilePaths);
                intent.putExtra(android.content.Intent.EXTRA_STREAM, mUris);
                intent.setType("application/*");
                startActivity(Intent.createChooser(intent, "Chooser"));
                mainListItemAdapter.setWithCB(false);
                mainListItemAdapter.notifyDataSetChanged();
                popupMenuDialog.dismiss();
                break;
            }

        }
    };

    /** mainListItemClickListener:the main list item click event listener */
    private OnItemClickListener mainListItemClickListener = new OnItemClickListener()
    {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id)
        {
            if (!mainListItemAdapter.isWithCB())
            {
                String mFileName = getFileNameInList(position);
                File mFile = new File(getPath(mFileName));
                if (!mFile.exists())
                {
                    mFile.mkdirs();
                }
                if (mFile.isDirectory())
                {
                    pathStringArray.add(mFileName);
                    setTabButton();
                    drawListView();
                } else
                {
                    openFile(mFile);
                }
            } else
            {
                mainListItemAdapter.setisChecked(position);
                mainListItemAdapter.setDataNotChange();
                mainListItemAdapter.notifyDataSetChanged();
                if (isChecked())
                {
                    moreFunctionButton.setEnabled(true);
                    deleteFunctionButton.setEnabled(true);
                } else
                {
                    moreFunctionButton.setEnabled(false);
                    deleteFunctionButton.setEnabled(false);
                }
            }
        }
    };

    /**
     * onRootTabButtonClickListener:the root button of path-bar click event
     * listener
     */
    private OnClickListener onRootTabButtonClickListener = new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            pathStringArray.clear();
            deleteTabButton(pathStringArray.size());
            setTabButton();
            drawListView();
        }
    };

    /** onTabButtonClickListener:the button of path-bar click event listener */
    private OnClickListener onTabButtonClickListener = new OnClickListener()
    {

        @Override
        public void onClick(View v)

        {

            pathStringArray = (List<String>) v.getTag();
            deleteTabButton(pathStringArray.size());
            setTabButton();
            drawListView();
        }
    };

    /*****************************/
    /* event listener code --end */
    /*****************************/
    private void moveMutiple()
    {
        new MoveMutiple().execute(srcPathsArray);
    }

    private void copyMutiple()
    {
        new CopyMutiple().execute(srcPathsArray);
    }

    /**
     * get all uris of the paths
     * 
     * @param the
     *            source paths
     * @return the uris
     * @return ArrayList<Uri>
     * @exception
     */
    private ArrayList<Uri> getAllUris(ArrayList<String> mPaths)
    {
        ArrayList<Uri> mUris = new ArrayList<Uri>();
        File mFile;
        for (int i = 0; i < mPaths.size(); i++)
        {
            mFile = new File(mPaths.get(i));
            if (mFile.isFile())
            {
                mUris.add(Uri.fromFile(mFile));
            }
        }
        return mUris;
    }

    /**
     * get the selected item's path
     * 
     * @return the paths of the selected item
     * @return ArrayList<String>
     * @exception
     */
    private ArrayList<String> getSelectPaths()
    {

        ArrayList<String> mSelectedPaths = new ArrayList<String>();
        if (!mainListItemAdapter.isSelectAll())
        {
            boolean[] isItemChecked = mainListItemAdapter.getItemChecked();
            for (int i = 0; i < isItemChecked.length; i++)
            {
                if (isItemChecked[i])
                {
                    String mFileName = (String) mainListItemList.get(i).get(
                            LIST_ITEM_TEXT_MAP_KEY);
                    mSelectedPaths.add(getPath(mFileName));
                }
            }
        } else
        {
            for (int i = 0; i < mainListItemList.size(); i++)
            {
                String mFileName = (String) mainListItemList.get(i).get(
                        LIST_ITEM_TEXT_MAP_KEY);
                mSelectedPaths.add(getPath(mFileName));
            }
        }
        return mSelectedPaths;
    }

    /**
     * share single file open the system app-chooser
     * 
     * @param the
     *            file which will be shared
     * @return void
     * @exception
     */
    private void shareFile(File mFile)
    {
        Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.putExtra(android.content.Intent.EXTRA_STREAM,
                Uri.fromFile(mFile));
        intent.setType(getMIMEType(mFile));
        startActivity(Intent.createChooser(intent, "Chooser"));
    }

    /**
     * add a file item to the main list
     * 
     * @param mFileName
     *            - the file name
     * @return void
     * @exception
     */
    private void addFile(String mFileName)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(LIST_ITEM_IMG_MAP_KEY, R.drawable.unknown_file);
        map.put(LIST_ITEM_TEXT_MAP_KEY, mFileName);
        mainListItemList.add(map);
    }

    /**
     * add a normal folder to the main list
     * 
     * @param mFolderName
     *            - the folder name
     * @return void
     * @exception
     */
    private void addFolder(String mFolderName)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(LIST_ITEM_IMG_MAP_KEY, R.drawable.folder_selector);
        map.put(LIST_ITEM_TEXT_MAP_KEY, mFolderName);
        mainListItemList.add(map);
    }

    /**
     * add the root button of the path-bar
     * 
     * @param mFolderDeep
     *            - the depth of the paths
     * @return void
     * @exception
     */
    private void addTabButton(int mFolderDeep)
    {
        for (int j = 0, i = (mFolderDeep < 3 ? (0) : (mFolderDeep - 3)); i < mFolderDeep; j++, i++)
        {
            // List<String> mPathStringArray = pathStringArray.subList(0,
            // (mFolderDeep<(2-j)?mFolderDeep-1:(mFolderDeep-2+j)));
            List<String> mPathStringArray = pathStringArray.subList(0, i + 1);
            tabButtons[j].setText(pathStringArray.get(i));
            tabButtons[j].setTag(mPathStringArray);
            tabButtons[j].setVisibility(View.VISIBLE);
        }
        setBluePoint(mFolderDeep);
    }

    /**
     * get the real name in the position of the list
     * 
     * @param the
     *            item's position in list
     * @return the real name of the item
     * @return String
     * @exception
     */
    private String getFileNameInList(int position)
    {
        String mFileName = mainListItemList.get(position)
                .get(LIST_ITEM_TEXT_MAP_KEY).toString();
        if (pathStringArray.size() == 0)
        {
            switch (position)
            {
            case 0:
                mFileName = systemFolderMap.get(SYSTEM_FOLDER_CAMERA);
                break;
            case 1:
                mFileName = systemFolderMap.get(SYSTEM_FOLDER_DOWNLOAD);
                break;
            case 2:
                mFileName = systemFolderMap.get(SYSTEM_FOLDER_MUSIC);
                break;
            case 3:
                mFileName = systemFolderMap.get(SYSTEM_FOLDER_PHOTO);
                break;
            case 4:
                mFileName = systemFolderMap.get(SYSTEM_FOLDER_VIDEO);
                break;
            }
        }
        return mFileName;
    }

    /**
     * set if the dialog can be closed by pressed button
     * 
     * @param dialog
     * @param closeDialog
     *            true - can be closed; false - can not be closed
     * @return void
     * @exception
     */
    private void closeDialog(DialogInterface dialog, boolean closeDialog)
    {
        try
        {
            Field field;
            field = dialog.getClass().getSuperclass()
                    .getDeclaredField("mShowing");
            field.setAccessible(true);
            field.set(dialog, closeDialog);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    /**
     * estimate if select paths conclude folder
     * 
     * @return true - contain folder; false - not contain folder;
     * @return boolean
     * @exception
     */
    private boolean containFolder()
    {
        ArrayList<String> mPaths = getSelectPaths();
        File mFile;
        for (int i = 0; i < mPaths.size(); i++)
        {
            mFile = new File(mPaths.get(i));
            if (mFile.isDirectory())
            {
                return true;
            }
        }
        return false;
    }

    /**
     * delete the button of the path-bar
     * 
     * @param mFolderDeep
     *            - the depth of the paths
     * @return void
     * @exception
     */
    private void deleteTabButton(int mFolderDeep)
    {

        for (int i = 2; i >= (mFolderDeep > 2 ? 2 : mFolderDeep); i--)
        {
            tabButtons[i].setVisibility(View.GONE);
        }
    }

    /**
     * draw the main list(include redraw)
     * 
     * @return void
     * @exception
     */
    private void drawListView()
    {
        mainListItemList.removeAll(mainListItemList);
        if (pathStringArray.size() == 0)
        {
            initSystemListItem();
        }
        String currentPath = getPath();
        File[] mFiles = getFiles(currentPath);
        for (int i = 0; i < mFiles.length; i++)
        {
            if (mFiles[i].isDirectory())
            {
                String mFileName = mFiles[i].getName().toLowerCase();
                if ((pathStringArray.size() == 0) & isSystemPathName(mFileName))
                {
                    continue;
                }
                addFolder(mFiles[i].getName());
            } else
            {
                String mFileName = mFiles[i].getName().toLowerCase();
                if ((pathStringArray.size() == 0) & isSystemPathName(mFileName))
                {
                    continue;
                }
                addFile(mFiles[i].getName());
            }
        }
        if (copyType == MOVE_MULTIPLE || copyType == MOVE_SINGLE_FILE
                || copyType == MOVE_SINGLE_FOLDER || copyType == COPY_MULTIPLE)
        {
            if (srcPath.equals(getPath()))
            {
                saveFunctionButton.setEnabled(false);
            } else
            {
                saveFunctionButton.setEnabled(true);
            }
        }
        mainListItemAdapter.notifyDataSetChanged();
    }

    /**
     * move a single folder
     * 
     * @return void
     * @exception
     */
    private void moveSingleFile()
    {
        String mFileName = getContextFile();
        File mFile = new File(tarPath + '/' + mFileName);
        if (mFile.exists())
        {
            new AlertDialog.Builder(this)
                    .setTitle(
                            mFileName
                                    + getResources().getString(
                                            R.string.file_exist))
                    .setPositiveButton(R.string.instead,
                            new DialogInterface.OnClickListener()
                            {

                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which)
                                {
                                    File mSrcFile = new File(srcPath + '/'
                                            + getContextFile());
                                    File mTarFile = new File(tarPath + '/'
                                            + getContextFile());
                                    new MoveSingleFile().execute(mSrcFile,
                                            mTarFile);
                                }
                            })
                    .setNegativeButton(R.string.cancel,
                            new DialogInterface.OnClickListener()
                            {

                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which)
                                {

                                }
                            }).show();
        } else
        {
            new MoveSingleFile().execute(new File(srcPath + '/' + mFileName),
                    mFile);

        }
    }

    /**
     * move a single folder
     * 
     * @return void
     * @exception
     */
    private void moveSingleFolder()
    {
        String mFileName = getContextFile();

        File mFile = new File(tarPath + '/' + mFileName);
        if (mFile.exists())
        {
            new AlertDialog.Builder(this)
                    .setTitle(
                            mFileName
                                    + getResources().getString(
                                            R.string.file_exist))
                    .setPositiveButton(R.string.instead,
                            new DialogInterface.OnClickListener()
                            {

                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which)
                                {
                                    File mSrcFile = new File(srcPath + '/'
                                            + getContextFile());
                                    File mTarFile = new File(tarPath + '/'
                                            + getContextFile());
                                    new MoveSingleFolder().execute(mSrcFile,
                                            mTarFile);
                                }
                            })
                    .setNegativeButton(R.string.cancel,
                            new DialogInterface.OnClickListener()
                            {

                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which)
                                {

                                }
                            }).show();
        } else
        {
            new MoveSingleFolder().execute(new File(srcPath + '/' + mFileName),
                    mFile);

        }

    }

    /**
     * copy a single folder
     * 
     * @return void
     * @exception
     */
    private void copySingleFolder()
    {
        String mFileName = getContextFile();
        if (srcPath.equals(tarPath))
        {
            File mFile = new File(tarPath + '/' + mFileName);
            String mFileName_new = "";
            for (int i = 1; mFile.exists(); i++)
            {

                if (1 == i)
                {
                    mFileName_new = mFileName + "_"
                            + getResources().getString(R.string.a_copy_of);
                } else
                {
                    mFileName_new = mFileName + "_"
                            + getResources().getString(R.string.a_copy_of)
                            + "(" + i + ")";
                }
                mFile = new File(tarPath + '/' + mFileName_new);
            }
            new CopySingleFolder().execute(new File(srcPath + '/' + mFileName),
                    mFile);

        } else
        {
            File mFile = new File(tarPath + '/' + mFileName);
            if (mFile.exists())
            {
                new AlertDialog.Builder(this)
                        .setTitle(
                                mFileName
                                        + getResources().getString(
                                                R.string.file_exist))
                        .setPositiveButton(R.string.instead,
                                new DialogInterface.OnClickListener()
                                {

                                    @Override
                                    public void onClick(DialogInterface dialog,
                                            int which)
                                    {
                                        File mSrcFile = new File(srcPath + '/'
                                                + getContextFile());
                                        File mTarFile = new File(tarPath + '/'
                                                + getContextFile());
                                        new CopySingleFolder().execute(
                                                mSrcFile, mTarFile);
                                    }
                                })
                        .setNegativeButton(R.string.cancel,
                                new DialogInterface.OnClickListener()
                                {

                                    @Override
                                    public void onClick(DialogInterface dialog,
                                            int which)
                                    {

                                    }
                                }).show();
            } else
            {
                new CopySingleFolder().execute(new File(srcPath + '/'
                        + mFileName), mFile);

            }
        }
    }

    /**
     * copy a single file
     * 
     * @throws IOException
     * @return void
     * @exception
     */
    private void copySingleFile() throws IOException
    {
        String mFileName = getContextFile();
        if (srcPath.equals(tarPath))
        {
            File mFile = new File(tarPath + '/' + mFileName);
            String mFileName_new = "";
            for (int i = 1; mFile.exists(); i++)
            {

                if (1 == i)
                {
                    mFileName_new = mFileName.substring(0,
                            mFileName.indexOf("."))
                            + "_"
                            + getResources().getString(R.string.a_copy_of)
                            + mFileName.substring(mFileName.indexOf("."));
                } else
                {
                    mFileName_new = mFileName.substring(0,
                            mFileName.indexOf("."))
                            + "_"
                            + getResources().getString(R.string.a_copy_of)
                            + "("
                            + i
                            + ")"
                            + mFileName.substring(mFileName.indexOf("."));
                }
                mFile = new File(tarPath + '/' + mFileName_new);
            }
            new CopySingleFile().execute(new File(srcPath + '/' + mFileName),
                    mFile);

        } else
        {
            File mFile = new File(tarPath + '/' + mFileName);
            if (mFile.exists())
            {
                new AlertDialog.Builder(this)
                        .setTitle(
                                mFileName
                                        + getResources().getString(
                                                R.string.file_exist))
                        .setPositiveButton(R.string.instead,
                                new DialogInterface.OnClickListener()
                                {

                                    @Override
                                    public void onClick(DialogInterface dialog,
                                            int which)
                                    {
                                        File mSrcFile = new File(srcPath + '/'
                                                + getContextFile());
                                        File mTarFile = new File(tarPath + '/'
                                                + getContextFile());
                                        mTarFile.delete();
                                        new CopySingleFile().execute(mSrcFile,
                                                mTarFile);
                                    }
                                })
                        .setNegativeButton(R.string.cancel,
                                new DialogInterface.OnClickListener()
                                {

                                    @Override
                                    public void onClick(DialogInterface dialog,
                                            int which)
                                    {

                                    }
                                }).show();
            } else
            {
                new CopySingleFile().execute(
                        new File(srcPath + '/' + mFileName), mFile);

            }
        }
    }

    /**
     * get the file-list of the path
     * 
     * @param mPath
     *            - the file path
     * @return - the file list of the file path
     * @return File[]
     * @exception
     */
    private File[] getFiles(String mPath)
    {
        File mFile = new File(mPath);
        File[] mFiles = mFile.listFiles();
        return mFiles;
    }

    /**
     * get MIME type
     * 
     * @param mFile
     *            - the file which will be gotten the MIME type
     * @return the MIME type
     * @return String
     * @exception
     */
    private String getMIMEType(File mFile)
    {
        String type = "";
        String fName = mFile.getName();
        String end = fName
                .substring(fName.lastIndexOf(".") + 1, fName.length())
                .toLowerCase();
        if (end.equals("m4a") || end.equals("mp3") || end.equals("mid")
                || end.equals("xmf") || end.equals("ogg") || end.equals("wav"))
        {
            type = "audio";
        } else if (end.equals("3gp") || end.equals("mp4"))
        {
            type = "video";
        } else if (end.equals("jpg") || end.equals("gif") || end.equals("png")
                || end.equals("jpeg") || end.equals("bmp"))
        {
            type = "image";
        } else if (end.equals("apk"))
        {
            type = "application/vnd.android.package-archive";
        } else
        {
            type = "*";
        }
        if (end.equals("apk"))
        {
        } else
        {
            type += "/*";
        }
        return type;
    }

    /**
     * get the whole path from the pathStringArray
     * 
     * @return - the gotten path
     * @return String
     * @exception
     */
    private String getPath()
    {
        String currentPath = SD_ROOTPATH;
        for (int i = 0; i < pathStringArray.size(); i++)
        {
            currentPath += '/';
            currentPath += pathStringArray.get(i);
        }
        return currentPath;
    }

    private String getContextFile()
    {
        return popupMenuHeaderTextView.getText().toString();
    }

    /**
     * get the path from the pathStringArray base on depth
     * 
     * @param mFolderDeep
     *            - the depth of the path which will be gotten
     * @return - the gotten path
     * @return String
     * @exception
     */
    private String getPath(int mFolderDeep)
    {
        String currentPath = SD_ROOTPATH;
        for (int i = 0; i < mFolderDeep; i++)
        {
            currentPath += '/';
            currentPath += pathStringArray.get(i);
        }
        return currentPath;
    }

    /**
     * get the path form the pathStringArray and estimate if it is the system
     * path
     * 
     * @param mFileName
     *            - the file which will be estimated
     * @return - the real path
     * @return String
     * @exception
     */
    private String getPath(String mFileName)
    {
        String currentPath = getPath();

        if (SD_ROOTPATH.equals(currentPath))
        {
            if (isSystemFolder(mFileName))
            {
                currentPath += '/';
                currentPath += systemFolderMap.get(mFileName);
            } else
            {
                currentPath += '/';
                currentPath += mFileName;
            }
        } else
        {
            currentPath += '/';
            currentPath += mFileName;
        }
        return currentPath;
    }

    /**
     * initialize the input dialog
     * 
     * @return void
     * @exception
     */
    private void initInputDialog()
    {
        inputDialog = new AlertDialog.Builder(this).create();
        View mView = View.inflate(inputDialog.getContext(),
                R.layout.input_dialog, null);
        inputDialog.setView(mView);
        inputDialog.setTitle(getResources().getString(R.string.new_folder));
        inputDialog.setButton(getResources().getString(R.string.submit),
                new DialogInterface.OnClickListener()
                {

                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        if (isNewFolder)
                        {
                            TextView mTV = (TextView) inputDialog
                                    .findViewById(R.id.inputDialogEdit);
                            String mFileName = "";
                            mFileName = mTV.getText().toString();
                            if (mFileName.equals(""))
                            {
                                closeDialog(dialog, false);
                                mTV.setError(getResources().getString(
                                        R.string.can_not_be_null));
                            } else
                            {
                                File mFile = new File(getPath(mFileName));
                                if (mFile.exists() && mFile.isDirectory())
                                {
                                    closeDialog(dialog, false);
                                    String mFileName_new = "";
                                    for (int i = 1; mFile.exists()
                                            && mFile.isDirectory(); i++)
                                    {

                                        if (1 == i)
                                        {
                                            mFileName_new = mFileName
                                                    + "_"
                                                    + getResources().getString(
                                                            R.string.a_copy_of);
                                        } else
                                        {
                                            mFileName_new = mFileName
                                                    + "_"
                                                    + getResources().getString(
                                                            R.string.a_copy_of)
                                                    + "(" + i + ")";
                                        }
                                        mFile = new File(getPath(mFileName_new));
                                    }
                                    mTV.setText(mFileName_new);
                                } else
                                {
                                    closeDialog(dialog, true);
                                    pathStringArray.add(mFileName);
                                    mFile.mkdirs();
                                    drawListView();
                                    setTabButton();
                                    mTV.setText("");

                                }
                            }
                        } else
                        {

                            TextView mTV = (TextView) inputDialog
                                    .findViewById(R.id.inputDialogEdit);
                            File mSrcFile = new File(getPath(getContextFile()));
                            String mFileName = "";
                            mFileName = mTV.getText().toString();
                            if (mFileName.equals(""))
                            {
                                closeDialog(dialog, false);
                                mTV.setError(getResources().getString(
                                        R.string.can_not_be_null));
                            } else
                            {
                                File mTarFile = new File(getPath(mFileName));
                                if (mTarFile.exists())
                                {
                                    closeDialog(dialog, false);
                                    String mFileName_new = "";
                                    for (int i = 1; mTarFile.exists()
                                            && mTarFile.isDirectory(); i++)
                                    {

                                        if (1 == i)
                                        {
                                            mFileName_new = mFileName
                                                    + "_"
                                                    + getResources().getString(
                                                            R.string.a_copy_of);
                                        } else
                                        {
                                            mFileName_new = mFileName
                                                    + "_"
                                                    + getResources().getString(
                                                            R.string.a_copy_of)
                                                    + "(" + i + ")";
                                        }
                                        mTarFile = new File(
                                                getPath(mFileName_new));
                                    }
                                    mTV.setText(mFileName_new);
                                } else
                                {
                                    closeDialog(dialog, true);

                                    mSrcFile.renameTo(mTarFile);
                                    drawListView();
                                    setTabButton();
                                    mTV.setText("");
                                }
                            }
                        }
                    }
                });
        inputDialog.setButton2(getResources().getString(R.string.cancel),
                new DialogInterface.OnClickListener()
                {

                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        // do noting and close dialog
                        closeDialog(dialog, true);
                        TextView mTV = (TextView) inputDialog
                                .findViewById(R.id.inputDialogEdit);
                        mTV.setText("");
                    }
                });

    }

    /**
     * sort the files in main list by size
     * 
     * @return void
     * @exception
     */
    private void sortFileList()
    {
        mainListItemList.removeAll(mainListItemList);
        if (pathStringArray.size() == 0)
        {
            initSystemListItem();
        }
        String currentPath = getPath();
        File[] mFiles = getFiles(currentPath);
        Arrays.sort(mFiles);
        Arrays.sort(mFiles, new FileSort.SortBySize());
        for (int i = 0; i < mFiles.length; i++)
        {
            if (mFiles[i].isDirectory())
            {
                String mFileName = mFiles[i].getName().toLowerCase();
                if ((pathStringArray.size() == 0) & isSystemPathName(mFileName))
                {
                    continue;
                }
                addFolder(mFiles[i].getName());
            } else
            {
                String mFileName = mFiles[i].getName().toLowerCase();
                if ((pathStringArray.size() == 0) & isSystemPathName(mFileName))
                {
                    continue;
                }
                addFile(mFiles[i].getName());
            }
        }
        if (copyType == MOVE_MULTIPLE || copyType == MOVE_SINGLE_FILE
                || copyType == MOVE_SINGLE_FOLDER || copyType == COPY_MULTIPLE)
        {
            if (srcPath.equals(getPath()))
            {
                saveFunctionButton.setEnabled(false);
            } else
            {
                saveFunctionButton.setEnabled(true);
            }
        }
        mainListItemAdapter.notifyDataSetChanged();
    }

    /**
     * initialize the popup menu
     * 
     * @return void
     * @exception
     */
    private void initPopupMenu()
    {
        popupMenuDialog = new AlertDialog.Builder(this).create();
        popupMenuListView = (ListView) View.inflate(this, R.layout.popup_menu,
                null);
        View mView = View.inflate(popupMenuListView.getContext(),
                R.layout.popup_menu_header, null);
        popupMenuListView.addHeaderView(mView, null, false);
        popupMenuHeaderTextView = (TextView) mView
                .findViewById(R.id.popupMenuHeaderText);

        popupMenuDialog.setView(popupMenuListView, 0, 0, 0, 0);
        popupMenuDialog.setOnKeyListener(new OnKeyListener()
        {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode,
                    KeyEvent event)
            {
                if (keyCode == KeyEvent.KEYCODE_MENU)
                    dialog.dismiss();

                return false;
            }
        });

        morePopupMenuAdapter = new SimpleAdapter(this, morePopupMenuItemList,
                R.layout.popup_menu_item, new String[] {
                        LIST_ITEM_TEXT_MAP_KEY, LIST_ITEM_IMG_MAP_KEY },
                new int[] { R.id.popupMenuText, R.id.popupMenuImg });

        contextPopupMenuAdapter = new SimpleAdapter(this,
                contextPopupMenuItemList, R.layout.popup_menu_item,
                new String[] { LIST_ITEM_TEXT_MAP_KEY, LIST_ITEM_IMG_MAP_KEY },
                new int[] { R.id.popupMenuText, R.id.popupMenuImg });
    }

    /**
     * initialize the progress bar
     * 
     * @return true - SD card is exist; false - SD card is not exist
     * @return boolean
     * @exception
     */
    private boolean initProgressBar()
    {
        String state = Environment.getExternalStorageState();
        if (state.equals(Environment.MEDIA_MOUNTED))
        {
            File sdFile = Environment.getExternalStorageDirectory();
            StatFs sf = new StatFs(sdFile.getPath());
            long size = sf.getBlockSize();
            long total = sf.getBlockCount();
            long free = sf.getAvailableBlocks();
            int usedInt = (int) ((1 - (double) free / total) * 100);
            double freeDouble = (double) ((double) free * size / 1024 / 1024 / 1024);
            double usedDouble = (double) ((double) (total - free) * size / 1024
                    / 1024 / 1024);
            String freeString = String.format("%1$.1f", freeDouble);
            String usedString = String.format("%1$.1f", usedDouble);
            String[] mArr = getResources().getStringArray(
                    R.array.progress_bar_texts);
            progressBarText.setText(mArr[0] + usedString + mArr[1] + freeString
                    + mArr[2]);
            progressBar.setProgress(usedInt);
            return true;
        } else
        {
            return false;
        }
    }

    private void deleteFolder(File mFile)
    {
        new DeleteFolder().execute(mFile);
    }

    /**
     * initialize the confirm delete dialog
     * 
     * @return void
     * @exception
     */
    private void initConfirmDeleteDialog()
    {
        AlertDialog.Builder mADB = new AlertDialog.Builder(this);
        mADB.setMessage(getResources().getString(R.string.confirm_delete) + "?");
        mADB.setPositiveButton(R.string.YES,
                new DialogInterface.OnClickListener()
                {

                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        File mFile = new File(getPath(getContextFile()));
                        if (mFile.exists())
                        {
                            deleteFolder(mFile);
                            Toast.makeText(FileExplorer.this,
                                    R.string.deleting, Toast.LENGTH_SHORT)
                                    .show();
                        }
                    }
                });
        mADB.setNegativeButton(R.string.NO,
                new DialogInterface.OnClickListener()
                {

                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {

                    }
                });
        confirmDeleteDialog = mADB.create();
    }

    /**
     * add the system item of the main list
     * 
     * @return void
     * @exception
     */
    private void initSystemListItem()
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(LIST_ITEM_IMG_MAP_KEY, R.drawable.camera_selector);
        map.put(LIST_ITEM_TEXT_MAP_KEY, SYSTEM_FOLDER_CAMERA);
        mainListItemList.add(map);
        map = new HashMap<String, Object>();
        map.put(LIST_ITEM_IMG_MAP_KEY, R.drawable.download_selector);
        map.put(LIST_ITEM_TEXT_MAP_KEY, SYSTEM_FOLDER_DOWNLOAD);
        mainListItemList.add(map);
        map = new HashMap<String, Object>();
        map.put(LIST_ITEM_IMG_MAP_KEY, R.drawable.music_selector);
        map.put(LIST_ITEM_TEXT_MAP_KEY, SYSTEM_FOLDER_MUSIC);
        mainListItemList.add(map);
        map = new HashMap<String, Object>();
        map.put(LIST_ITEM_IMG_MAP_KEY, R.drawable.photo_selector);
        map.put(LIST_ITEM_TEXT_MAP_KEY, SYSTEM_FOLDER_PHOTO);
        mainListItemList.add(map);
        map = new HashMap<String, Object>();
        map.put(LIST_ITEM_IMG_MAP_KEY, R.drawable.video_selector);
        map.put(LIST_ITEM_TEXT_MAP_KEY, SYSTEM_FOLDER_VIDEO);
        mainListItemList.add(map);
    }

    /**
     * get if these is any item selected
     * 
     * @return true - at least one item is selected; false - nothing is selected
     * @return boolean
     * @exception
     */
    private boolean isChecked()
    {
        boolean[] isItemChecked = mainListItemAdapter.getItemChecked();

        for (int i = 0; i < isItemChecked.length; i++)
            if (isItemChecked[i])
            {
                return true;
            }
        return false;
    }

    /**
     * estimate if it is the system folder name
     * 
     * @param mFileName
     *            - the file which will be estimated
     * @return true - it's a system folder path; false - it's not a system
     *         folder path
     * @return boolean
     * @exception
     */
    private boolean isSystemFolder(String mFileName)
    {
        if (mFileName.equals(SYSTEM_FOLDER_CAMERA)
                || mFileName.equals(SYSTEM_FOLDER_DOWNLOAD)
                || mFileName.equals(SYSTEM_FOLDER_MUSIC)
                || mFileName.equals(SYSTEM_FOLDER_PHOTO)
                || mFileName.equals(SYSTEM_FOLDER_VIDEO))
        {
            return true;
        }
        return false;
    }

    /**
     * estimate if it is the system path
     * 
     * @param mFileName
     *            - the file name
     * @return true - it is a system path; false - it is not a system path
     * @return boolean
     * @exception
     */
    private boolean isSystemPathName(String mFileName)
    {
        if (mFileName.equals(systemFolderMap.get("Video").toLowerCase())
                || mFileName.equals(systemFolderMap.get("Download")
                        .toLowerCase())
                || mFileName.equals(systemFolderMap.get("Photo").toLowerCase())
                || mFileName
                        .equals(systemFolderMap.get("Camera").toLowerCase())
                || mFileName.equals(systemFolderMap.get("Music").toLowerCase()))
        {
            return true;
        }
        return false;
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        // TODO oncreate
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;

        bluePointPositionMap[3] = width - 10;
        optionMenu = new MyOptionMenu(this);
        optionMenu.setGridViewItemClickListener(optionMenuItemClickListener);
        progressBarText = (TextView) findViewById(R.id.pbTV);
        pathBar = (RelativeLayout) findViewById(R.id.pathBar);
        progressBar = (ProgressBar) findViewById(R.id.progressBar1);
        rootTabButton = (Button) findViewById(R.id.rootTabButton);
        mainListView = (ListView) findViewById(R.id.main_list_view);
        SDNotExistImageView = (ImageView) findViewById(R.id.SDNotExistImageView);
        SDNotExistTextView = (TextView) findViewById(R.id.SDNotExistTextView);
        tabButtons[0] = (Button) findViewById(R.id.tabButton1);
        tabButtons[1] = (Button) findViewById(R.id.tabButton2);
        tabButtons[2] = (Button) findViewById(R.id.tabButton3);
        saveFunctionButton = (Button) findViewById(R.id.saveButton);
        cancelFunctionButton = (Button) findViewById(R.id.cancelButton);
        selectAllFunctionButton = (Button) findViewById(R.id.chooseAllButton);
        deleteFunctionButton = (Button) findViewById(R.id.deleteButton);
        moreFunctionButton = (Button) findViewById(R.id.moreButton);
        functionButtonBar = (RelativeLayout) findViewById(R.id.functionButtonBar);
        bluePoint = (ImageView) findViewById(R.id.bluePointIM);
        bottomBar = (RelativeLayout) findViewById(R.id.bottomBar);
        deleteFunctionButton
                .setOnClickListener(deleteFunctionButtonClickListener);
        cancelFunctionButton
                .setOnClickListener(cancelFunctionButtonClickListener);
        moreFunctionButton.setOnClickListener(moreFunctionButtonClickListener);
        saveFunctionButton.setOnClickListener(saveFunctionButtonClickListener);
        selectAllFunctionButton
                .setOnClickListener(selectAllFunctionButtonClickListener);
        mainListItemAdapter = new LVCBSimpleAdapter(this, mainListItemList,
                R.layout.list_item, new String[] { LIST_ITEM_IMG_MAP_KEY,
                        LIST_ITEM_TEXT_MAP_KEY }, new int[] {
                        R.id.listItemImage, R.id.listItemText });
        mainListView.setAdapter(mainListItemAdapter);
        mainListView.setOnItemClickListener(mainListItemClickListener);
        mainListView.setOnItemLongClickListener(mainListItemLongClickListener);
        rootTabButton.setOnClickListener(onRootTabButtonClickListener);
        initPopupMenu();
        initInputDialog();
        initConfirmDeleteDialog();
        for (int i = 0; i < 3; i++)
        {
            tabButtons[i].setOnClickListener(onTabButtonClickListener);
        }

    }

    @Override
    protected void onResume()
    {
        super.onResume();
        if (initProgressBar())
        {
            mainListView.setVisibility(View.VISIBLE);
            pathBar.setVisibility(View.VISIBLE);
            SDNotExistImageView.setVisibility(View.GONE);
            SDNotExistTextView.setVisibility(View.GONE);
            drawListView();
        } else
        {
            mainListView.setVisibility(View.GONE);
            pathBar.setVisibility(View.GONE);
            SDNotExistImageView.setVisibility(View.VISIBLE);
            SDNotExistTextView.setVisibility(View.VISIBLE);
        }
    }

    /* create the option menu */
    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {

        menu.add("menu");
        return super.onCreateOptionsMenu(menu);
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {

        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            boolean noWindowOpen = true;
            if (mainListItemAdapter.isWithCB())
            {
                noWindowOpen = false;
                mainListItemAdapter.setWithCB(false);
                mainListItemAdapter.notifyDataSetChanged();
            }
            if (popupMenuDialog.isShowing())
            {
                noWindowOpen = false;
                popupMenuDialog.dismiss();
            }
            if (functionButtonBar.getVisibility() == View.VISIBLE)
            {
                noWindowOpen = false;
                setFunctionbar(true);
            }
            if (optionMenu.isShowing())
            {
                noWindowOpen = false;
                optionMenu.dismiss();
            }
            if (noWindowOpen && event.getRepeatCount() == 0)
            {
                if ((System.currentTimeMillis() - exitTime) > 2000)
                {
                    Toast.makeText(this, R.string.exit_infomation,
                            Toast.LENGTH_SHORT).show();
                    exitTime = System.currentTimeMillis();
                } else
                {
                    finish();
                    System.exit(0);
                }
                return true;
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);

    }

    /* option menu opened */
    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onMenuOpened(int, android.view.Menu)
     */
    @Override
    public boolean onMenuOpened(int featureId, Menu menu)
    {
        if (!optionMenu.isShowing())
        {
            optionMenu.showAtLocation(findViewById(R.id.mainLayout),
                    Gravity.BOTTOM, 0, 0);
        } else
        {
            optionMenu.dismiss();
        }
        return false;
    }

    /**
     * open the file
     * 
     * @param mFile
     *            - the file will be opened
     * @return void
     * @exception
     */
    private void openFile(File mFile)
    {
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction(android.content.Intent.ACTION_VIEW);

        String type = getMIMEType(mFile);
        intent.setDataAndType(Uri.fromFile(mFile), type);
        startActivity(intent);
    }

    /**
     * set the position of blue point
     * 
     * @param mFolderDeep
     *            - the depth of the paths
     * @return void
     * @exception
     */
    private void setBluePoint(int mFolderDeep)
    {
        LayoutParams margin = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
        margin.leftMargin = bluePointPositionMap[mFolderDeep > 3 ? 3
                : mFolderDeep];
        margin.topMargin = 21;
        bluePoint.setLayoutParams(margin);
    }

    /**
     * set popup menu as context popup menu and open it
     * 
     * @param mFileName
     *            - the context file name
     * @return void
     * @exception
     */
    private void setContextPopupMenu(String mFileName, boolean isFolder)
    {
        contextPopupMenuItemList.removeAll(contextPopupMenuItemList);
        String[] mString = getResources().getStringArray(
                R.array.context_popup_menu_text);
        int[] img = { R.drawable.copy_normal, R.drawable.mobile_normal,
                R.drawable.rename_normal, R.drawable.delete_normal,
                R.drawable.share_normal };
        Map<String, Object> mMap;
        for (int i = 0; i < (isFolder ? 4 : 5); i++)
        {
            mMap = new HashMap<String, Object>();
            mMap.put(LIST_ITEM_TEXT_MAP_KEY, mString[i]);
            mMap.put(LIST_ITEM_IMG_MAP_KEY, img[i]);
            contextPopupMenuItemList.add(mMap);
        }
        popupMenuHeaderTextView.setText(mFileName);
        popupMenuListView.setAdapter(contextPopupMenuAdapter);
        popupMenuListView.setOnItemClickListener(contextPopupItemClickListener);
        popupMenuDialog.show();
    }

    /**
     * set the statement of the function button
     * 
     * @param isThree
     *            true - contains three buttons; false - contains two buttons
     * @return void
     * @exception
     */
    private void setFunction(boolean isThree)
    {
        if (isThree)
        {
            selectAllFunctionButton.setVisibility(View.VISIBLE);
            moreFunctionButton.setVisibility(View.VISIBLE);
            deleteFunctionButton.setVisibility(View.VISIBLE);
            saveFunctionButton.setVisibility(View.GONE);
            cancelFunctionButton.setVisibility(View.GONE);
        } else
        {
            selectAllFunctionButton.setVisibility(View.GONE);
            moreFunctionButton.setVisibility(View.GONE);
            deleteFunctionButton.setVisibility(View.GONE);
            saveFunctionButton.setVisibility(View.VISIBLE);
            cancelFunctionButton.setVisibility(View.VISIBLE);
        }
    }

    /**
     * set the statement of the function-bar
     * 
     * @param isThree
     *            true - contains thres buttons; false -contains two buttons;
     * @return void
     * @exception
     */
    private void setFunctionbar(boolean isThree)
    {
        if (View.GONE == functionButtonBar.getVisibility())
        {
            setFunction(isThree);
            if (!isThree)
            {
                RelativeLayout.LayoutParams params = (LayoutParams) bottomBar
                        .getLayoutParams();
                params.height = 105;
                bottomBar.setLayoutParams(params);
            }
            functionButtonBar.setVisibility(View.VISIBLE);
        } else
        {
            RelativeLayout.LayoutParams params = (LayoutParams) bottomBar
                    .getLayoutParams();
            params.height = 51;
            bottomBar.setLayoutParams(params);
            functionButtonBar.setVisibility(View.GONE);
        }
    }

    /**
     * set popup menu as "more" popup menu and open it
     * 
     * @param isThree
     *            true - contains three item; false - contains two item
     * @return void
     * @exception
     */
    private void setMorePopupMenu(boolean isThree)
    {
        morePopupMenuItemList.removeAll(morePopupMenuItemList);
        String[] mText = getResources().getStringArray(
                R.array.more_popup_menu_text);
        int[] img = { R.drawable.copy_normal, R.drawable.mobile_normal,
                R.drawable.share_normal };
        Map<String, Object> mMap;
        for (int i = 0; i < (isThree ? 3 : 2); i++)
        {
            mMap = new HashMap<String, Object>();
            mMap.put(LIST_ITEM_TEXT_MAP_KEY, mText[i]);
            mMap.put(LIST_ITEM_IMG_MAP_KEY, img[i]);
            morePopupMenuItemList.add(mMap);
        }
        popupMenuHeaderTextView.setText(getResources().getString(
                R.string.more_popup_menu_title));
        popupMenuListView.setAdapter(morePopupMenuAdapter);
        popupMenuListView.setOnItemClickListener(morePopupItemClickListener);
        popupMenuDialog.show();
    }

    /**
     * set the path button on path-bar
     * 
     * @return void
     * @exception
     */
    private void setTabButton()
    {
        int mFolderDeep = pathStringArray.size();
        deleteTabButton(mFolderDeep);
        addTabButton(mFolderDeep);
    }

    private void reCalSize()
    {
        if (initProgressBar())
        {
            mainListView.setVisibility(View.VISIBLE);
            pathBar.setVisibility(View.VISIBLE);
            SDNotExistImageView.setVisibility(View.GONE);
            SDNotExistTextView.setVisibility(View.GONE);
            drawListView();
        } else
        {
            mainListView.setVisibility(View.GONE);
            pathBar.setVisibility(View.GONE);
            SDNotExistImageView.setVisibility(View.VISIBLE);
            SDNotExistTextView.setVisibility(View.VISIBLE);
        }
    }

    /* show log */
    private void showLog()
    {
        Log.i("test", "test");
    }
}